﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;

namespace MyTestProject {


    public class TestTexture {
        [Fact]
        public void TestConstructor () {
            var img = new Image2D (Image2D.RGB, 16, 16);
            var tex = new Texture2D (img);

            Assert.Equal (img, tex.ImageBase);
            Assert.Equal (Texture2D.FilterNearest, tex.ImageFilter);
            Assert.Equal (Texture2D.FilterBaseLevel, tex.LevelFilter);
        }

        [Fact]
        public void TestSetFiltering () {
            var img = new Image2D (Image2D.RGB, 16, 16);
            var tex = new Texture2D (img);

            tex.SetFiltering (Texture2D.FilterBaseLevel, Texture2D.FilterNearest);

            Assert.Equal (Texture2D.FilterNearest, tex.ImageFilter);
            Assert.Equal (Texture2D.FilterBaseLevel, tex.LevelFilter);
        }

        [Fact]
        public void TestReferences () {
            var img = new Image2D (Image2D.RGB, 16, 16);
            var tex = new Texture2D (img);

            var refs = tex.References;

            Assert.Equal (1, refs.Length);
            Assert.Same (img, refs[0]);
        }

        [Fact]
        public void TestDuplicate () {
            var img = new Image2D (Image2D.RGB, 16, 16);
            var tex = (Texture)new Texture2D (img);
            tex.SetFiltering (Texture2D.FilterBaseLevel, Texture2D.FilterNearest);
            tex.UserID = 100;

            var dup = (Texture)tex.Duplicate ();

            Assert.Equal (tex.ImageBase, dup.ImageBase);
            Assert.Equal (tex.ImageFilter, dup.ImageFilter);
            Assert.Equal (tex.LevelFilter, dup.LevelFilter);
            Assert.Equal (tex.UserID, dup.UserID);
        }
    }
}
